package blackstar.agent.event;

/**
 * @author RayWoo (ayufox@gmail.com)
 * 
 */
public abstract class EventMediator implements EventDispatcher
{
	private static EventMediator INSTANCE = new DefaultEventMediator();

	public static void setInstance(EventMediator instance)
	{
		if (instance == null)
		{
			throw new IllegalArgumentException("instance can't be null");
		}
		INSTANCE = instance;
	}

	public abstract void dispatch(Event event);

	public abstract void register(EventListener eventListener);

	/**
	 * 注册Listener
	 * @param eventListener
	 */
	public static void registerListener(EventListener eventListener)
	{
		INSTANCE.register(eventListener);
	}

	/**
	 * 分发事件被关注的监听者
	 * @param event
	 */
	public static void dispatchEvent(Event event)
	{
		INSTANCE.dispatch(event);
	}
}
